package com.xyc.servlet.user;

import com.xyc.mapper.UserMapper;
import com.xyc.pojo.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/findUser")
public class FindUserServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //跳转到一个更新页面  修改数据，再提交回myUser请求
        req.setCharacterEncoding("utf-8");
        //获取要更新的uuid
        String id = req.getParameter("id_update");
        //System.out.println("需要更新的uuid"+id);

        //根据uuid进行查询 返回一条User
        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        UserMapper userMapper = ctx.getBean("userMapper", UserMapper.class);
        User user = userMapper.selectUserById(id);
        //System.out.println("需要更新的user"+user);
        req.setAttribute("user", user); // 将更新之前的数据先改善到updateUser.jsp页面上以供修改


        //点击更新跳转到某一个页面，进行修改
        req.getRequestDispatcher("user/updateUser.jsp").forward(req, resp);

    }
}
